{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "0c63cd89",
   "metadata": {},
   "outputs": [],
   "source": [
    "from eye2 import EyeSensor\n",
    "import time\n",
    "\n",
    "import jtoollib as jt\n",
    "from pic_window import *\n",
    "\n",
    "import math\n",
    "import pandas as pd\n",
    "\n",
    "import numpy as np\n",
    "\n",
    "from pywinauto import Application\n",
    "import psutil"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b013ee59",
   "metadata": {},
   "source": [
    "# 获取精测窗口进程，并根据auto_id绑定测量按钮"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "45d2736c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "JC EYE-2\n"
     ]
    }
   ],
   "source": [
    "# # 1. 先用 psutil 找到进程\n",
    "for proc in psutil.process_iter(['pid', 'name']):\n",
    "\n",
    "    if proc.info['name'] == \"jcColorAnalyzer.exe\":\n",
    "        pid = proc.info['pid']\n",
    "        break\n",
    "else:\n",
    "    raise RuntimeError(\"未找到 jcColorAnalyzer.exe 进程\")\n",
    "\n",
    "# 2. 连接到该进程\n",
    "app = Application(backend=\"uia\").connect(process=pid)\n",
    "\n",
    "# 3. 拿到主窗口\n",
    "dlg = app.top_window()\n",
    "print(dlg.window_text())\n",
    "\n",
    "index = dlg.child_window(auto_id=\"jcColorAnalyzerClass.centralWidget.groupBox.tabWidget.qt_tabwidget_stackedwidget.dialog.gb_messetting.pbMeasure\", control_type=\"Button\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9800883d",
   "metadata": {},
   "source": [
    "# 测试W曲线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "78884e70",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 扫描JI2C\n",
    "devices = jt.scan_devices_sn()\n",
    "# 开启JI2C\n",
    "handle = jt.open_device(devices[0])\n",
    "\n",
    "L0_Y = []\n",
    "\n",
    "try:\n",
    "    for i in range(0x30,0x54,1):\n",
    "    # 14 WU for i in range(0x30,0x61,1):\n",
    "        jt.i2c_write_no_reg(handle=handle, addr=0x9E, data=[ (i<<1)&0xFE])\n",
    "\n",
    "        time.sleep(0.2)\n",
    "\n",
    "        index.click()\n",
    "        time.sleep(1.2)\n",
    "\n",
    "\n",
    "finally:\n",
    "    jt.jtool.DevClose(handle)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "16cee12b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
